**
**  Political Economy of Consumer Debt Relief
**
**  Code for Precinct-level Analysis
**
**  July 2024
**  

clear all
cd  "/Users/zas/Library/CloudStorage/Dropbox/Vote Buying_shared/Georgia/!REStat/Replication"
use "precincts.dta"

xtset precinct_no term

* Dependent Variables

foreach v in zura vasha {
gen `v'_gr = (`v'-l1.`v')/l1.`v'
gen `v'_turn = `v' / Participant
}

label var zura_gr    "Zura growth"
label var vasha_gr   "Vasha growth"

* Independent Variables: Debt relief

foreach v in loans_no id_no debt_tot {
gen `v'_ln = log(`v')
}
label var id_no_ln    "log affected individuals"
label var debt_tot_ln "log cancelled debt"

foreach v in loans_no id_no debt_tot {
gen `v'_ln0 = log(`v'+1)
}
label var id_no_ln0    "log (affected individuals +1 )"
label var debt_tot_ln0 "log (cancelled debt + 1)"

replace debt_tot = debt_tot / 1000000000
label var debt_tot "debt in billions"
binscatter zura_gr debt_tot , genxq(debt_median_dummy) nq(2) line(connect)
label var debt_median_dummy  "Dummy for median of debt"

* Independent Variables: Controls etc.

foreach v in Participant Voter Turnout{
gen `v'_gr = (`v'-l1.`v')/l1.`v'
gen `v'_ln = log(`v')
gen     `v'_1_ln = `v'_ln     if term==1
replace `v'_1_ln = l1.`v'_1_ln if term==2
}

label var Voter_1_ln        "log registered voters"
label var Participant_1_ln  "log individuals voted"
label var Participant_gr    "Turnout growth"

gen other =  log(cand1 + cand2 +cand4 +cand10+ cand13+ cand17 +cand18+ cand21+ cand22+ cand23+ cand25+ cand27+ cand28+ cand30+ cand31+ cand35+ cand36+ cand40+ cand49+ cand51+ cand58 +cand62 +cand65)
label var other  "log votes for all other candidates in round i"

**
** Save treatment intensity data

preserve
drop if  term==1
keep precinct_no debt_tot_ln id_no_ln  debt_tot_ln0 id_no_ln0 
foreach v in  debt_tot_ln id_no_ln  debt_tot_ln0 id_no_ln0 {
rename `v' p_`v'
}
save "auxiliary_data/treatment_intensity_precincts.dta", replace
restore

***
*** Baseline Results

local controls1 Voter_1_ln Turnout_1_ln

** TABLE 2

foreach y in zura_gr vasha_gr Participant_gr{	
foreach x in  debt_tot_ln debt_tot_ln0  {
reg `y' `x' `controls1' if term==2
outreg2 using results/prec_base, label e(F) ctitle() tex(frag) dec(3) excel drop() sortvar(debt_tot_ln id_no_ln debt_tot debt_tot_ln0 id_no_ln0 debt_median_dummy  Voter_1_ln Participant_1_ln ) append
sum `y' if e(sample)==1
}
}

***
*** Dynamic Results

preserve

* Prepare data and merge with data on other elections

gen id = precinct_no
gen year=2018 if term==1
replace year=2019 if term==2
gen unm = vasha_turn *100
gen gd = zura_turn *100

merge m:m id year using "auxiliary_data/past_elections_precincts.dta"

* Define variables over time

xtset id year

foreach x in debt_tot_ln id_no_ln debt_tot_ln0 id_no_ln0 {
bysort id: egen `x'a = mean(`x')
drop `x'
rename `x'a `x'
}

gen     el=1 if year==2012
replace el=2 if year==2013
replace el=3 if year==2016
replace el=4 if year==2018
replace el=5 if year==2019
replace el=6 if year==2020

xtset id el
foreach v in gd unm{
gen `v'_gr = (`v'-l1.`v')/l1.`v'
gen `v'_ln = log(`v')
}

binscatter gd_gr debt_tot_ln0 if el==2, genxq(debt2g) nq(2) line(connect) by(year)
binscatter gd_gr debt_tot_ln0 if el==2, genxq(debt5g) nq(5) line(connect) by(year)

** Figure 2 Panel B (Baseline)

qui bysort id (debt2g): replace debt2g=debt2g[1]
reg gd_gr i.debt2g##ib(4).el if el>2
coefplot, vertical drop(_cons) ytitle("Growth in GD votes in high vs low intesnity precincts")  ylabel(-.1(.1).3) keep(2.debt2g#1.el 2.debt2g#2.el 2.debt2g#3.el 2.debt2g#4.el 2.debt2g#5.el 2.debt2g#6.el) yline(0)  baselevels omitted coeflabels(2.debt2g#1.el = 2012 2.debt2g#2.el = 2013 2.debt2g#3.el = 2016 2.debt2g#4.el = 2018(i) 2.debt2g#5.el = 2018(ii) 2.debt2g#6.el = 2020, wrap(20) notick labcolor() labsize(medlarge) labgap()) scheme(s2mono)
graph export "results/Trends_median_growth.pdf", as(pdf) replace

** Figure C2 Panel B (Appendix)

qui bysort id (debt5g): replace debt5g=debt5g[1]
gen sample = 1 if debt5g==1 | debt5g==5 
reg gd_gr i.debt5g##ib(4).el if el>2 & sample==1
coefplot, vertical drop(_cons) ytitle("Growth in GD votes in high vs low intesnity precincts") keep(5.debt5g#1.el 5.debt5g#2.el 5.debt5g#3.el 5.debt5g#4.el 5.debt5g#5.el 5.debt5g#6.el) yline(0)  baselevels omitted coeflabels(5.debt5g#1.el = 2012 5.debt5g#2.el = 2013 5.debt5g#3.el = 2016 5.debt5g#4.el = 2018(i) 5.debt5g#5.el = 2018(ii) 5.debt5g#6.el = 2020, wrap(20) notick labcolor() labsize(medlarge) labgap()) scheme(s2mono)
graph export "results/Trends_quint_growth.pdf", as(pdf) replace

restore


***
*** Appendix Robustness Results

** Table C1 Panel B (Results with Individuals)

foreach y in zura_gr vasha_gr Participant_gr{	
foreach x in  id_no_ln id_no_ln0{
reg `y' `x' `controls1' if term==2
outreg2 using results/prec_c1, label e(F) ctitle() tex(frag) dec(3) excel drop() sortvar(debt_tot_ln id_no_ln debt_tot debt_tot_ln0 id_no_ln0 debt_median_dummy  Voter_1_ln Participant_1_ln ) append
sum `y' if e(sample)==1
}
}

** Table C2 Panel A (Results with District Fixed Effects)

local controls3 Voter_1_ln Turnout_1_ln  i.district_no

foreach y in zura_gr vasha_gr Participant_gr{
foreach x in  debt_tot_ln debt_tot_ln0  id_no_ln id_no_ln0 {
reg `y' `x' `controls3' if term==2
outreg2 using results/prec_c2a, label e(F) ctitle() tex(frag) dec(3) excel drop() sortvar(debt_tot_ln id_no_ln debt_tot_ln0 id_no_ln0 debt_tot Voter_1_ln Participant_1_ln Turnout_1_ln) append
}
}

** Table C2 Panel B (Results Without Tbilisi)

foreach y in zura_gr vasha_gr Participant_gr{
foreach x in  debt_tot_ln debt_tot_ln0  id_no_ln id_no_ln0 {
reg `y' `x' `controls1' if term==2 & district_special != 1
outreg2 using results/prec_c2b, label e(F) ctitle() tex(frag) dec(3) excel drop() sortvar(debt_tot_ln id_no_ln debt_tot debt_median_dummy debt_tot_ln0 id_no_ln0 Voter_1_ln Participant_1_ln ) append
}
}

** Table C4 Columns 4-6 (Treatment Effects by Low-vs-High Debt Intensity)

foreach y in zura_gr vasha_gr Participant_gr{
foreach x in debt_median_dummy{
reg `y' `x' if term==2
outreg2 using results/prec_c4, label e(F) ctitle() tex(frag) dec(3) excel drop() sortvar(debt_tot_ln id_no_ln debt_tot debt_median_dummy debt_tot_est id_no_est  Voter_1_ln Participant_1_ln ) append
}
}
*}

** Table C5 Panel B (Treatment Effects Controlling for Other Candidates Votes)

local controls2 Voter_1_ln Turnout_1_ln other

foreach y in zura_gr vasha_gr Participant_gr{
foreach x in  debt_tot_ln debt_tot_ln0 id_no_ln id_no_ln0 {
reg `y' `x' `controls2' if term==2
outreg2 using results/prec_c5, label e(F) ctitle() tex(frag) dec(3) excel drop() sortvar(debt_tot_ln id_no_ln debt_tot debt_median_dummy debt_tot_est id_no_est  Voter_1_ln Participant_1_ln ) append
}
}

** Figure C4 a and b (Marginal Effects on Votes Depending on Turnout Growth)

reg zura_gr c.debt_tot_ln##c.Participant_gr Voter_1_ln Turnout_1_ln  if term==2
margins, dydx(debt_tot_ln) at(Participant_gr=(-1(.25)3))
marginsplot, yline(0) graphregion(color(white)) legend(off) title("") xtitle(Growth in Turnout) legend() addplot(hist Participant_gr , mcolor(gs12%50) below yaxis(2) yscale(range(0(1)15) alt axis(2))) scheme(s2mono)
graph export "results/prec_zura_turnout_debt.pdf", as(pdf) replace

reg vasha_gr c.debt_tot_ln##c.Participant_gr Voter_1_ln Turnout_1_ln  if term==2
margins, dydx(debt_tot_ln) at(Participant_gr=(-1(.25)3))
marginsplot, yline(0) graphregion(color(white)) legend(off) title("") xtitle(Growth in Turnout) legend() addplot(hist Participant_gr , mcolor(gs12%50) below yaxis(2) yscale(range(0(1)15) alt axis(2))) scheme(s2mono)
graph export "results/prec_vasha_turnout_debt.pdf", as(pdf) replace


** Figure C4 c and d (Marginal Effects on Votes Depending on Other Candidates Votes in Round i)

reg zura_gr c.debt_tot_ln##c.other Voter_1_ln Turnout_1_ln  if term==2
margins, dydx(debt_tot_ln) at(other=(0(.5)6))
marginsplot, yline(0) graphregion(color(white)) legend(off) title("") xtitle(Log Other Candidates Votes in Round i) legend() addplot(hist other , mcolor(gs12%50) below yaxis(2) yscale(range(0(1)5) alt axis(2))) scheme(s2mono)
graph export "results/prec_zura_other_debt.pdf", as(pdf) replace

reg vasha_gr c.debt_tot_ln##c.other Voter_1_ln Turnout_1_ln  if term==2
margins, dydx(debt_tot_ln) at(other=(0(.5)6))
marginsplot, yline(0) graphregion(color(white)) legend(off) title("") xtitle(Log Other Candidates Votes in Round i) legend() addplot(hist other , mcolor(gs12%50) below yaxis(2) yscale(range(0(1)5) alt axis(2))) scheme(s2mono)
graph export "results/prec_vasha_other_debt.pdf", as(pdf) replace
